import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)
/* Layout */
import Layout from '@/layout'

export const constantRoutes = [{
		path: '/login',
		component: () => import('@/views/login/index'),
		hidden: true
	},
	{
		path: '/404',
		component: () => import('@/views/404'),
		hidden: true
	},
	{
		path: '/',
		component: Layout,
		redirect: '/home',
		children: [{
			path: 'home',
			name: 'home',
			component: () => import('@/views/home/index'),
			meta: {
				title: '首页',
				icon: 'el-icon-house'
			}
		}]
	},
	{
		path: '/shouxufei',
		component: Layout,
		children: [{
			path: 'shouxufei',
			name: 'shouxufei',
			component: () => import('@/views/shouxufei/index'),
			meta: {
				title: '手续费配置',
				icon: 'el-icon-setting'
			}
		}]
	},
	// {
	// 	path: '/',
	// 	component: Layout,
	// 	redirect: '/shouxufei',
	// 	children: [{
	// 		path: 'shouxufei',
	// 		name: 'shouxufei',
	// 		component: () => import('@/views/shouxufei/index'),
	// 		meta: {
	// 			title: '手续费配置',
	// 			icon: 'el-icon-setting'
	// 		}
	// 	}]
	// },
	{
		path: '/user',
		component: Layout,
		children: [{
				path: 'user',
				name: 'User',
				component: () => import('@/views/dashboard/index'),
				meta: {
					title: '用户',
					icon: 'dashboard'
				}
			},
			// {
			//   path: 'shouyi',
			//   name: 'shouyi',
			//   component: () => import('@/views/shouyi/index'),
			//   meta: { title: '收益', icon: 'form' },
			//   hidden: true,
			// }
		]
	},
	{
		path: '/viporder',
		component: Layout,
		children: [{
			path: 'viporder',
			name: 'viporder',
			component: () => import('@/views/viporder/index'),
			meta: {
				title: '购买记录',
				icon: 'el-icon-shopping-cart-1'
			}
		}]
	},
	{
		path: '/copywriting',
		component: Layout,
		children: [{
			path: 'copywriting',
			name: 'copywriting',
			component: () => import('@/views/copywriting/index'),
			meta: {
				title: '转单记录',
				icon: 'el-icon-edit-outline'
			}
		}]
	},
	{
		path: '/shouhou',
		component: Layout,
		children: [{
			path: 'shouhou',
			name: 'shouhou',
			component: () => import('@/views/shouhou/index'),
			meta: {
				title: '售后退款',
				icon: 'form'
			}
		}]
	},
	{
		path: '/vippackage',
		component: Layout,
		children: [{
			path: 'vippackage',
			name: 'vippackage',
			component: () => import('@/views/vippackage/index'),
			meta: {
				title: '提现记录',
				icon: 'el-icon-bank-card'
			}
		}]
	},
	{
		path: '/chongzhi',
		component: Layout,
		children: [{
			path: 'chongzhi',
			name: 'chongzhi',
			component: () => import('@/views/chongzhi/index'),
			meta: {
				title: '充值记录',
				icon: 'el-icon-money'
			}
		}]
	},
	{
		path: '/types',
		component: Layout,
		children: [{
			path: 'types',
			name: 'types',
			component: () => import('@/views/types/index'),
			meta: {
				title: '分类',
				icon: 'el-icon-tickets'
			}
		}]
	},
	{
		path: '/yybuser',
		component: Layout,
		children: [{
			path: 'yybuser',
			name: 'yybuser',
			component: () => import('@/views/yybuser/index'),
			meta: {
				title: '运营宝用户',
				icon: 'form'
			}
		}]
	},
	{
		path: '/usermangement',
		component: Layout,
		children: [{
			path: 'usermangement',
			name: 'usermangement',
			component: () => import('@/views/usermangement/index'),
			meta: {
				title: '账户管理',
				icon: 'el-icon-user'
			}
		}]
	},
	{
		path: '/rolemangement',
		component: Layout,
		children: [{
			path: 'rolemangement',
			name: 'rolemangement',
			component: () => import('@/views/rolemangement/index'),
			meta: {
				title: '角色管理',
				icon: 'el-icon-s-custom'
			}
		}]
	},
	{
		path: '/operationlog',
		component: Layout,
		children: [{
			path: 'operationlog',
			name: 'operationlog',
			component: () => import('@/views/operationLog/index'),
			meta: {
				title: '操作日志',
				icon: 'el-icon-tickets'
			}
		}]
	},
	{
		path: '/pullback',
		component: Layout,
		children: [{
			path: 'pullback',
			name: 'pullback',
			component: () => import('@/views/pullback/index'),
			meta: {
				title: '反馈记录',
				icon: 'el-icon-crop'
			}
		}]
	},
	{
		path: '/scanLog',
		component: Layout,
		children: [{
			path: 'scanLog',
			name: 'scanLog',
			component: () => import('@/views/scanLog/index'),
			meta: {
				title: '浏览记录',
				icon: 'el-icon-aim'
			}
		}]
	},
	{
		path: '/proSetting',
		component: Layout,
		children: [{
			path: 'proSetting',
			name: 'proSetting',
			component: () => import('@/views/proSetting/index'),
			meta: {
				title: '推广配置',
				icon: 'el-icon-s-tools'
			}
		}]
	},
	{
		path: '/openTicket',
		component: Layout,
		children: [{
			path: 'openTicket',
			name: 'openTicket',
			component: () => import('@/views/openTicket/index'),
			meta: {
				title: '开票管理',
				icon: 'el-icon-s-finance'
			}
		}]
	},
	{
		path: '*',
		redirect: '/404',
		hidden: true
	}
]

// 需要重新执行这里 路由才能生效 
const createRouter = () => new Router({
	// mode: 'history', // require service support
	scrollBehavior: () => ({
		y: 0
	}),
	routes: constantRoutes
})

const router = createRouter()

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
	const newRouter = createRouter()
	router.matcher = newRouter.matcher // reset router
}
export function setRouter() {
	JSON.parse(localStorage.getItem('sidermenu')).forEach(item => {
		router.addRoute(item)
	})
}

export default router